package com.jz.community.moduleshoppingguide.home.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gongwen.marqueen.MarqueeFactory;
import com.jz.community.basecomm.base.BaseHtml5Activity;
import com.jz.community.basecomm.base.BaseX5WebActivity;
import com.jz.community.basecomm.utils.RxDataTool;
import com.jz.community.moduleshoppingguide.R;
import com.jz.community.moduleshoppingguide.home.bean.HomeFindBean;


/**
 * Created by Andy Huang on 2018/4/25.
 *
 * @description:
 */
public class ComplexViewMF extends MarqueeFactory<RelativeLayout, HomeFindBean.EmbeddedBean.ContentBean.ChunnelHomePageBean> {
    private LayoutInflater inflater;

    public ComplexViewMF(Context mContext) {
        super(mContext);
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    protected RelativeLayout generateMarqueeItemView(HomeFindBean.EmbeddedBean.ContentBean.ChunnelHomePageBean data) {
        RelativeLayout mView = (RelativeLayout) inflater.inflate(R.layout.module_shoppingguide_complex_view, null);
        if (!RxDataTool.isNullString(data.getLabel())) {
            ((TextView) mView.findViewById(R.id.tv_new_user_gift)).setText(data.getLabel());
        } else {
            mView.findViewById(R.id.tv_new_user_gift).setVisibility(View.GONE);
        }
        ((TextView) mView.findViewById(R.id.tv_marquee_text)).setText(data.getName());
        mView.findViewById(R.id.tv_marquee_text).setOnClickListener(v -> {
            Intent intent = new Intent(mContext, BaseX5WebActivity.class);
            intent.putExtra("title", data.getName());
            intent.putExtra("url", data.getUrl());
            mContext.startActivity(intent);
        });
        return mView;
    }
}
